import { GET_COURSE_CATALOGUE, GET_COURSE_DETAIL, GET_TEACHER_DETAIL } from "../../service/course"

export default {
  state: () => ({
    courseDetail: {},
    catalogues: [],
    teacherDetail: {}
  
  }),

  getters: {
    currentVideoSrc (state) {
      return state.catalogues[0]?.children[0].resources
    }

  },

  mutations: {
    setCourseList (state, detail) {
      state.courseDetail = detail
    },

    setCatalogues (state, list) {
      state.catalogues = list
    },

    setTeacherDetail (state, teacher) {
      state.teacherDetail = teacher
    },

    
  },

  actions: {

    async getCourseDetail ({commit, dispatch}, id) {
      const res = await GET_COURSE_DETAIL(id)
      
      console.log(res)

      commit('setCourseList', res)
      // 获取到课程详情后，拿着teacherid请求讲师详情
      const teacherId = res.teacher
      dispatch('getTeacherDetail', teacherId)
    },

    async getCatalogues ({commit}, id) {
      const res = await GET_COURSE_CATALOGUE(id)
      commit('setCatalogues', res)

    },

    async getTeacherDetail ({commit}, id) {
      const res = await GET_TEACHER_DETAIL(id)
      commit('setTeacherDetail', res)
    }
  }
}